package com.easy.flux;

import com.easy.flux.web.entity.Balance;
import com.easy.flux.web.repository.BalanceRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @Packge com.easy
 * @Autor linNaibin
 * @Description
 * @Version 1.0
 * @Date 2021/1/12 17:33
 */


@SpringBootApplication
public class WebFluxApplication {

    public static void main(String[] args) {
        System.out.println("Hello World!");

        ConfigurableApplicationContext conn = null;
        try {
            conn = SpringApplication.run(WebFluxApplication.class, args);
            // test db
            BalanceRepository repository = conn.getBean(BalanceRepository.class);
            Flux<Balance> balance = repository.findAll();

            balance.flatMap(e -> {
                if (StringUtils.isEmpty(e.getAcNo())) {
                    return Mono.just(e);
                } else {
                    return Mono.empty();
                }
            }).subscribe(System.out::println, System.err::println, () -> {
                System.out.println(" end .");
            });

            //   balance.subscribe(System.out::println);
            //
        } catch (Exception e) {
            e.printStackTrace();
        }


        WebClient webClient = WebClient.create("");
        System.out.println("启动完毕...");
    }

}